package com.lagou.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;


@Activate(group = {CommonConstants.CONSUMER,CommonConstants.PROVIDER})
public class TransportIPFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        RpcContext context = RpcContext.getContext();
        if(context.isConsumerSide()){
            String remoteHost = context.getRemoteHost();
            context.setAttachment("remoteHost",remoteHost);
        }else if(context.isProviderSide()){
            Object o1 = context.getAttachment("remoteHost");
            System.out.println("remoteHost："+o1);
        }
        return  invoker.invoke(invocation);
    }
}
